//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.rmfyzxfw.caseprocess.boot.result;

import cn.hutool.core.date.DateUtil;
import com.rmfyzxfw.caseprocess.enums.StatusCodeEnum;
import lombok.Data;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;

import java.io.Serializable;

@Data
public class ApiResult<T> implements Serializable {
    private String requestId;
    private Integer code;
    private String message;
    private String errorCode;
    private T data;
    private String timestamp;

    public static <T> ApiResult<T> success(T data) {
        return success(StatusCodeEnum.SC200.getMsg(), data);
    }

    public static <T> ApiResult<T> success(String msg, T data) {
        ApiResult<T> apiResult = base();
        apiResult.setCode(StatusCodeEnum.SC200.getCode());
        apiResult.setMessage(msg);
        apiResult.setData(data);
        return apiResult;
    }

    public static <T> ApiResult<T> fail(Integer code, String msg) {
        ApiResult<T> apiResult = base();
        apiResult.setCode(code);
        apiResult.setMessage(msg);
        return apiResult;
    }

    public static <T> ApiResult<T> fail(Integer code, String msg, String errorCode) {
        ApiResult<T> apiResult = base();
        apiResult.setCode(code);
        apiResult.setErrorCode(errorCode);
        apiResult.setMessage(msg);
        return apiResult;
    }

    public static <T> ApiResult<T> base() {
        String traceId = TraceContext.traceId();
        ApiResult<T> apiResult = new ApiResult();
        apiResult.setTimestamp(DateUtil.now());
        apiResult.setRequestId(traceId);
        return apiResult;
    }

    public ApiResult() {
    }







}
